﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>APS排产看板</title>
  <style>
    .green {
      color: #0fd850 !important;
    }

    /* 固定列部分分辨率下不能拖动bugfix */
    .el-table__fixed {
      height: auto !important;
      bottom: 20px !important;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <vue2-report-header :title="'APS排产看板'"></vue2-report-header>
    <div style="padding: 10px;" id="queryZone">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules"
        :disabled="formDisabled">
        <el-form-item label="组织结构:" prop="selectOrg">
          <el-cascader :options="orginazition" :props="{ checkStrictly: true}" ref="orginazitionRef"
            v-model="queryInfo.selectOrg" clearable style="width:300px;" @change="selectOrgChange">
          </el-cascader>
        </el-form-item>

        <el-form-item label="工人:">
          <el-select v-model="queryInfo.workerid" placeholder="请选择" clearable filterable style="width: 100px;">
            <el-option v-for="i in workerList" :key="i.employeeid" :label="i.fullname" :value="i.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='resourcename' label="设备:">
          <el-autocomplete v-model.trim="queryInfo.resourcename" placeholder="请输入设备编号" :trigger-on-focus="false"
            :fetch-suggestions="getResourcenameAsync" :value-key="'resourcename'" :debounce="500" style="width:200px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='mfgordername' label="订单号:">
          <el-autocomplete v-model.trim="queryInfo.mfgordername" placeholder="请输入订单号" :trigger-on-focus="false"
            :fetch-suggestions="searchMfgorderAsync" :value-key="'mfgordername'" :debounce="500" style="width:200px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='productname' label="件号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入件号" :trigger-on-focus="false"
            :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
            :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="排产时间:" prop="selectdate">
          <el-date-picker v-model="queryInfo.selectdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border height="650" ref="table">
        <el-table-column type="index" width="50" fixed></el-table-column>
        <el-table-column label="设备名称" prop="description" width="180" show-overflow-tooltip fixed></el-table-column>
        <el-table-column label="设备编号" prop="resourcename" width="180" show-overflow-tooltip></el-table-column>
        <el-table-column v-for="col in colums" :label="col.label" :key="col.value" :prop="col.value" width="300"
          align="center" :class-name="(col.day === '0' || col.day === '6')?'green':''">
          <template slot-scope="scope">
            <el-tag v-for="i in scope.row[col.value]" @click="showDetailInfo(i)" :type="setColor(i.status)">
              <el-popover placement="top-start" title="" width="300" trigger="hover">
                <i class="el-icon-info" slot="reference"></i>
                <div>
                  <strong>分厂：</strong>{{i.factoryname}}
                  <br />
                  <strong>工区：</strong>{{i.workcentername}}
                  <br />
                  <strong>班组：</strong>{{i.teamname}}
                  <br />
                  <strong>订单号：</strong>{{i.mfgordername}}
                  <br />
                  <strong>订单数：</strong>{{i.mfgqty}}
                  <br />
                  <strong>件号/批次：</strong>{{i.productname}}/{{i.containerno}}
                  <br />
                  <strong>零件名称：</strong>{{i.productdescription}}
                  <br />
                  <strong>流水卡号：</strong>{{i.containername}}
                  <br />
                  <strong>数量：</strong>{{i.qty}}
                  <br />
                  <strong>工序：</strong>{{i.workflowstepname}}
                  <br />
                  <strong>设备：</strong>{{i.description}}
                  <br />
                  <strong>工人：</strong>{{i.fullname}}
                  <br />
                  <strong>开始时间：</strong>{{i.starttime.replace('T',' ')}}
                  <br />
                  <strong>结束时间：</strong>{{i.endtime.replace('T',' ')}}
                  <br />
                  <strong>完工时间：</strong>{{i.checkdate? i.checkdate.replace('T',' ') :''}}
                  <br />
                  <strong>完工状态：</strong>{{i.status}}
                </div>
              </el-popover>
              <span style="margin:3px;cursor:pointer;">{{i.containername}}【{{i.specno}}】</span>
            </el-tag>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[queryInfo.pageSize,100,500]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <el-dialog :title="detail.title" :width="'100%'" :top="'10px'" :center="true"
        :visible.sync="detail.dialogVisiable">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="detail.dataList" stripe border>
          <el-table-column type="index" width="40"></el-table-column>
          <el-table-column label="分厂" prop="factoryname" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="工区" prop="workcentername" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="班组" prop="teamname" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="设备" prop="description" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="工人" prop="fullname" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="订单号" prop="mfgordername" width="160" show-overflow-tooltip></el-table-column>
          <el-table-column label="零件号" prop="productname" width="140" show-overflow-tooltip></el-table-column>
          <el-table-column label="零件名称" prop="productdescription" show-overflow-tooltip></el-table-column>
          <el-table-column label="批次号" prop="containername" width="180" show-overflow-tooltip></el-table-column>
          <el-table-column label="数量" prop="qty" width="60" show-overflow-tooltip></el-table-column>
          <el-table-column label="工序号" prop="specno" width="60" show-overflow-tooltip></el-table-column>
          <el-table-column label="工序内容" prop="opdesc" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="开始时间" prop="starttime" width="110" show-overflow-tooltip>
            <template slot-scope="scope" v-if="scope.row.starttime">
              <el-popover placement="top-start" title="" width="300" trigger="hover"
                :content="scope.row.starttime.replace('T',' ')">
                <i class="el-icon-info" slot="reference"></i>
              </el-popover>
              {{scope.row.starttime.split('T')[1]}}
            </template>
          </el-table-column>
          <el-table-column label="结束时间" prop="endtime" width="110" show-overflow-tooltip>
            <template slot-scope="scope" v-if="scope.row.endtime">
              <el-popover placement="top-start" title="" width="300" trigger="hover"
                :content="scope.row.endtime.replace('T',' ')">
                <i class="el-icon-info" slot="reference"></i>
              </el-popover>
              {{scope.row.endtime.split('T')[1]}}
            </template>
          </el-table-column>
          <el-table-column label="实际完工时间" prop="checkdate" width="110" show-overflow-tooltip>
            <template slot-scope="scope" v-if="scope.row.checkdate">
              <el-popover placement="top-start" title="" width="300" trigger="hover"
                :content="scope.row.checkdate.replace('T',' ')">
                <i class="el-icon-info" slot="reference"></i>
              </el-popover>
              {{scope.row.checkdate.split('T')[1]}}
            </template>
          </el-table-column>
          <el-table-column label="状态" prop="status" width="100" show-overflow-tooltip>
            <template slot-scope="scope" v-if="scope.row.status">
              <el-tag v-if="scope.row.status === '按时完成'" type="success">{{scope.row.status}}</el-tag>
              <el-tag v-else-if="scope.row.status === '超期完成'" type="warning">{{scope.row.status}}</el-tag>
              <el-tag v-else-if="scope.row.status === '超期未完'" type="danger">{{scope.row.status}}</el-tag>
              <el-tag v-else type="info">{{scope.row.status}}</el-tag>
            </template>
          </el-table-column>
        </el-table>
      </el-dialog>

      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { getParams, fetchSuggestion } from '../Scripts/hooks/useCommonMethod.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { getUserInfo, getWorkerList, getMESOrginazition } from '../Scripts/hooks/fetchAPI.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        queryInfo: {
          selectOrg: [],
          workerid: '',//工人
          resourcename: '',//设备
          mfgordername: '',//订单
          productname: '',//件号
          containername: '',//批次
          selectdate: '',//排产时间
          status: '',//完工状态
          currentPage: 1,//当前页
          pageSize: 10//每页显示条数
        },
        workerList: [],
        userInfo: {},
        orginazition: [],
        formDisabled: false,
        rules: { selectdate: [{ required: true, message: '筛选时间不能为空', trigger: 'change' }] },
        detail: { dialogVisiable: false, dataList: [], title: '' },
        colums: [],
        selectdateList: [],
        dataList: [],
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        setColor(status) {
          if (status === '按时完成') {
            return 'success';
          } else if (status === '超期完成') {
            return 'warning';
          } else if (status === '超期未完') {
            return 'danger';
          } else {
            return '';
          }
        },
        // 查询订单号
        searchMfgorderAsync(value, callback) {
          fetchSuggestion({ actionName: 'getMfgordernameAsync', name: 'mfgordername', value, callback });
        },
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback });
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback });
        },
        // 查询设备
        getResourcenameAsync(value, callback) {
          fetchSuggestion({ actionName: 'getResourcenameAsync', name: 'resourcename', value, callback });
        },
        async selectOrgChange(val) {
          this.queryInfo.workerid = null;
          if (val) {
            const [factoryid, workcenterid, teamid] = val;
            this.workerList = await getWorkerList({ factoryid, workcenterid, teamid });
          }
        },
        // 查询数据
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              const [start, end] = this.queryInfo.selectdate;
              const diff = dayjs(end).diff(dayjs(start), 'day');
              if (diff > 30) {
                return this.$message.error('时间范围不能超过30天');
              }
              this.colums = [];
              this.selectdateList = [];
              for (let i = 0; i <= diff; i++) {
                let value = dayjs(start).add(i, 'day').format('YYYY-MM-DD');
                let label = "";
                const d = dayjs(value).format('d');
                if (d === '0') {
                  label = `${value}【周日】`;
                } else if (d === '1') {
                  label = `${value}【周一】`;
                } else if (d === '2') {
                  label = `${value}【周二】`;
                } else if (d === '3') {
                  label = `${value}【周三】`;
                } else if (d === '4') {
                  label = `${value}【周四】`;
                } else if (d === '5') {
                  label = `${value}【周五】`;
                } else {
                  label = `${value}【周六】`;
                }
                this.colums.push({ value, label, day: d });
                this.selectdateList.push(value);
              }
              this.loading = true;
              this.loadingText = "数据加载中...";
              const { data: { data, total, meta } } = await axios.post('../handler/board/ApsPlanDashBoard.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo,
                colums: this.selectdateList
              })
              this.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.dataList = data;
              this.total = total;
              this.$refs["table"].doLayout();
            }
          })
        },
        showDetailInfo(row) {
          this.detail.title = `批次：${row.containername} 工序：${row.specno}-${row.opdesc} 排产详细信息`;
          this.detail.dialogVisiable = true;
          this.detail.dataList = [row];
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      async mounted() {
        const start = dayjs().startOf('month').format('YYYY-MM-DD');
        const end = dayjs().format('YYYY-MM-DD');
        // 筛选时间默认：本月1日~今天
        this.queryInfo.selectdate = [start, end];
        const diff = dayjs(end).diff(dayjs(start), 'day');
        this.colums = [];
        this.selectdateList = [];
        for (let i = 0; i <= diff; i++) {
          let value = dayjs(start).add(i, 'day').format('YYYY-MM-DD');
          let label = "";
          const d = dayjs(value).format('d');
          if (d === '0') {
            label = `${value}【周日】`;
          } else if (d === '1') {
            label = `${value}【周一】`;
          } else if (d === '2') {
            label = `${value}【周二】`;
          } else if (d === '3') {
            label = `${value}【周三】`;
          } else if (d === '4') {
            label = `${value}【周四】`;
          } else if (d === '5') {
            label = `${value}【周五】`;
          } else {
            label = `${value}【周六】`;
          }
          this.colums.push({ value, label, day: d });
          this.selectdateList.push(value);
        }
        this.orginazition = await getMESOrginazition({ factoryCode: '600|601|602|604|607|608|609' });
        this.userInfo = await getUserInfo({ employeeid: getParams("uid") });
        if (!this.userInfo) { this.formDisabled = true; return; }
        const { factoryid, workcenterid, teamid, auth, employeeid, employeename, fullname } = this.userInfo;
        if (auth === '工人') {
          this.queryInfo.selectOrg = [factoryid, workcenterid, teamid];
          this.workerList.push({ employeeid, employeename, fullname });
          this.queryInfo.workerid = employeeid;
        }
        if (auth === '班组长') {
          this.queryInfo.selectOrg = [factoryid, workcenterid, teamid];
          this.workerList = await getWorkerList({ factoryid, workcenterid, teamid });
        }
        if (auth === '工区长') {
          this.queryInfo.selectOrg = [factoryid, workcenterid];
          this.workerList = await getWorkerList({ factoryid, workcenterid });
        }
        if (auth === '管理员' && factoryid !== null) {
          this.queryInfo.selectOrg = [factoryid];
          this.workerList = await getWorkerList({ factoryid })
        }
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>